package course.exception;

import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Student stu = new Student();

        System.out.println("请输入姓名：");
        String name = sc.next();
        stu.setName(name);
        while (true){
            System.out.println("请输入年龄：");
            String ageStr = sc.next();
            try {
                int age = Integer.parseInt(ageStr);
                stu.setAge(age);
                break;
            }catch (NumberFormatException e){
                System.out.println("请输入一个整数");
            }catch (RuntimeException e){
                System.out.println("请输入一个符合范围的的年龄");
            }
        }
        System.out.println(stu);
    }
}
